# coding:utf-8

"""
    进程池 multiprocessing
        Pool 进程池    Processcount    进程池对象


        apply_async 任务加入进程池(异步) func，args 无
        close       关闭进程池         无          无
        join        等待进程池任务结束   无         无

    进程锁
        from multiprocessing import Manager
        manager = Manager()

"""
import multiprocessing
import os
import time


def work(count):
    print(count, os.getpid())
    time.sleep(2)
    return 'result is %s ,pid is %s'%(count, os.getpid())


if __name__ == '__main__':
    pool = multiprocessing.Pool(5)
    results = []
    # 往进程池中塞入20个任务
    for i in range(20):
        result = pool.apply_async(func=work, args=(i, ))
        results.append(result)

    for res in results:
        print(res.get())

    pool.close()
    pool.join()

